//
//  RecommendViewController.swift
//  KTDouYu
//
//  Created by CoolKi on 16/5/4.
//  Copyright © 2016年 CoolKi. All rights reserved.
//

import UIKit
import SDCycleScrollView

class RecommendViewController: UITableViewController {

    // MARK: Lazyload stored properties
    private lazy var scycleTupleArr : [(String,String)] = {
        let scycleTupleArr : [(String,String)] = [(String,String)]()
        return scycleTupleArr
    }()
    private lazy var scycleImgArr : [String] = {
        let scycleImgArr = [String]()
        return scycleImgArr
    }()
    private lazy var scycleTitleArr : [String] = {
        let scycleTitleArr = [String]()
        return scycleTitleArr
    }()
    private lazy var scycleScrollV : SDCycleScrollView = {
        let scycleScrollV = SDCycleScrollView(frame: CGRectMake(0, 0, screenW, 200), delegate: self, placeholderImage: placeImg)
        scycleScrollV.backgroundColor = UIColor.redColor()
        scycleScrollV.pageControlAliment = SDCycleScrollViewPageContolAlimentRight
        scycleScrollV.currentPageDotColor = UIColor.orangeColor()
        return scycleScrollV
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.brownColor()
        self.tableView.tableHeaderView = self.scycleScrollV
        get_scrollImgViewData()
        post_video()
    }
    
}

// MARK: UI
extension RecommendViewController : SDCycleScrollViewDelegate{
    func cycleScrollView(cycleScrollView: SDCycleScrollView!, didSelectItemAtIndex index: Int) {
        let detailVC = DetailViewController()
        self.navigationController?.pushViewController(detailVC, animated: true)
    }
}


// MARK: Http
extension RecommendViewController {
    func get_scrollImgViewData(){
        let parameterDic : [String : AnyObject] = ["aid":"ios","auth":"97d9e4d3e9dfab80321d11df5777a107","client_sys":"ios","time":String.kt_GetNowTime()]
        KTHttpTool().KT_GET(API_TOP_URLString, parameters: parameterDic, success: { (dataTask, response) -> () in
            guard let result = response else {
                //print(response)
                return
            }

            let responseDic = result as! [String : AnyObject]
            let array = responseDic["data"] as! [[String : AnyObject]]
            for tempDic in array {
                print(tempDic["pic_url"]!,tempDic["title"]!)
                let imgStr = tempDic["pic_url"] as! String
                let titleStr = tempDic["title"] as! String
                self.scycleImgArr.append(imgStr)
                self.scycleTitleArr.append(titleStr)
            }
            self.scycleScrollV.imageURLStringsGroup = self.scycleImgArr
            self.scycleScrollV.titlesGroup = self.scycleTitleArr
            self.tableView.reloadData()
            
            }) { (dataTask, error) -> () in
                //print(error)
        }
    }
    func post_video(){
        let parameterDic : [String : AnyObject] = ["aid":"ios","auth":"d938945b1b17bc02159aa504e2a53852","client_sys":"ios","time":"1462537020","place" : "7"]
        KTHttpTool().POST(TEST_URL, parameters: parameterDic, progress: nil, success: { (data : NSURLSessionDataTask,reponse : AnyObject?) -> Void in
            print("XXX~>\(reponse)")
            }) { (data: NSURLSessionDataTask?,error : NSError) -> Void in
                
        }
    }
    
}












